import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.geom.*;
import java.math.*;
import namespace.*;
public class mainProject 
{
	public static void main(String[] args)
	{
		
		mainFrame frame = new mainFrame();
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setVisible(true);
	}
}
class mainFrame extends JFrame
{
	public mainFrame()
	{
		setTitle("Project(KN-35)");
		setSize(dh,dw);
		JMenuBar bar = new JMenuBar();
		JMenu mainMenu = new JMenu("Main");//just try edit)
		JMenu helpManu = new JMenu("Help");
		JMenuItem exitItem = new JMenuItem("Exit");
		JMenuItem howItem = new JMenuItem("How to use");
		JMenuItem aboutDev = new JMenuItem("About Developers");
		JMenuItem startItem = new JMenuItem("Start");
		mainMenu.add(startItem);
		helpManu.add(howItem);
		mainMenu.add(aboutDev);
		mainMenu.add(exitItem);
		bar.add(mainMenu);
		bar.add(helpManu);
		add(bar,BorderLayout.NORTH);
		exitItem.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e)
			{
				System.exit(0);
			}
		});
		
		aboutDev.addActionListener(new ActionListener() 
		{
			public void actionPerformed(ActionEvent e2)
			{
				abdevDialog = new AboutDevDialog(mainFrame.this);
				abdevDialog.setVisible(true);
			}
		});	
		final JRadioButton ch1 = new JRadioButton("y = cos(t/sin(x))+N^sin(x)");
		final JRadioButton ch2 = new JRadioButton("y = x^(e^cos(t))/(N+1)^x");
		final JRadioButton ch3 = new JRadioButton("y =  (cosh(t*x)/e^V)+A");
		ch1.setEnabled(false);
		ch2.setEnabled(false);
		ch3.setEnabled(false);
		final JTextArea ar1 = new JTextArea();
		final JTextArea ar2 = new JTextArea();
		final JTextArea ar3 = new JTextArea();
		ar1.setEnabled(false);
		ar2.setEnabled(false);
		startItem.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent ee)
			{
				ch1.setEnabled(true);
				ch2.setEnabled(true);
				ar1.setEnabled(true);
				ar2.setEnabled(true);
				ch3.setEnabled(true);
			}
		});
		final JLabel l1 = new JLabel("Enter t :");
		final JLabel l2 = new JLabel("Enter N :");
		final JLabel l3 = new JLabel("Enter V :");
		JButton b1= new JButton("to build ");
		eastPanel = new JPanel();
		eastPanel.setLayout(new GridLayout(15,15));
		eastPanel.add(ch1);
		eastPanel.add(ch2);
		eastPanel.add(ch3);
		
		
		add(eastPanel,BorderLayout.WEST);
		southPanel = new JPanel();
		southPanel.add(b1);
		add(southPanel,BorderLayout.SOUTH);
		
		ch1.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e)
			{
				
					eastPanel.remove(l2);
		    		eastPanel.remove(l3);
		    		eastPanel.remove(ar1);
					eastPanel.remove(ar2);
					eastPanel.remove(ar3);
					ch2.setSelected(false);
					ch3.setSelected(false);
					eastPanel.add(l1);
					eastPanel.add(ar1);
					eastPanel.add(l2);
					eastPanel.add(ar2);
					eastPanel.updateUI();
					
			}
		});
		ch2.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e)
			{
				
					eastPanel.remove(l1);
			    	eastPanel.remove(l3);
			    	eastPanel.remove(ar1);
					eastPanel.remove(ar2);
					eastPanel.remove(ar3);
			    	ch1.setSelected(false);
					ch3.setSelected(false);
					eastPanel.add(l1);
					eastPanel.add(ar1);
					eastPanel.add(l2);
					eastPanel.add(ar2);
					eastPanel.updateUI();
				
			}
		});
		ch3.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e)
			{
					
				    eastPanel.remove(l1);
				    eastPanel.remove(l2);
				    eastPanel.remove(ar1);
				    eastPanel.remove(ar2);
				    eastPanel.remove(ar3);
					ch1.setSelected(false);
					ch2.setSelected(false);
					eastPanel.add(l1);
					eastPanel.add(ar1);
					eastPanel.add(l3);
					eastPanel.add(ar3);
					eastPanel.updateUI();
				
			}
		});
	
		b1.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e3)
			{
				if(ch1.isSelected())
				{
					try
					{
						String gt = ar1.getText();
						String gN = ar2.getText();
						//String gV = ar3.getText();
						double t = Double.parseDouble(gt);
						//int V = (int)Double.parseDouble(gV);
						double N = Double.parseDouble(gN);
						drawFunc fr = new drawFunc(t,N);
						fr.setVisible(true);
					}
					catch(NumberFormatException d)
					{
						ObDialog dv = new ObDialog(mainFrame.this);
						dv.setVisible(true);
					}
				}
				if(ch2.isSelected())
				{
					try
					{
						String gt = ar1.getText();
						String gN = ar2.getText();
						//String gV = ar3.getText();
						double t = Double.parseDouble(gt);
						//int V = (int)Double.parseDouble(gV);
						double N = Double.parseDouble(gN);
						drawFunc1 fr1 = new drawFunc1(t,N);
						fr1.setVisible(true);
					}
					catch(NumberFormatException d)
					{
						ObDialog dv = new ObDialog(mainFrame.this);
						dv.setVisible(true);
					}
				}
				if(ch3.isSelected())
				{
					try
					{
						String gt = ar1.getText();
						//String gN = ar2.getText();
						String gV = ar3.getText();
						double t = Double.parseDouble(gt);
						int V = (int)Double.parseDouble(gV);
						//double N = Double.parseDouble(gN);
						drawFunc2 fr2 = new drawFunc2(t,V);
						fr2.setVisible(true);
					}
					catch(NumberFormatException d)
					{
						ObDialog dv = new ObDialog(mainFrame.this);
						dv.setVisible(true);
					}
				}
				
			}
		});	
		
	}
	//private double t;
	//private int V;
	//private double N;
	//private String gt;
	//private String gN;
	//private String gV;
	private JPanel southPanel;
	private JPanel grPanel;
	private AboutDevDialog abdevDialog;
	private JPanel eastPanel;
	private JPanel buttonPanel;
	private static final int dh = 300;
	private static final int dw = 400;
}



class AboutDevDialog extends JDialog
{
	public AboutDevDialog(JFrame owner)
	{
		super(owner,"About developer",true);
		JLabel label1 = new JLabel("KN - 35 SAPR Lviv 2011");
		JLabel label2 = new JLabel(" :)");
		add(label2,BorderLayout.NORTH);
		add(label1,BorderLayout.SOUTH);
		JButton yes = new JButton("OK");
		JPanel panel = new JPanel();
		panel.add(yes);
		add(panel);
		yes.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e)
			{
				setVisible(false);
			}
		});
		setSize(350,150);
	}	
}
class ObDialog extends JDialog
{
	public ObDialog(JFrame owner)
	{
		super(owner,"Warning",true);
		JLabel label1 = new JLabel("Please, enter all data !");
		add(label1,BorderLayout.NORTH);
		JButton yes = new JButton("OK");
		JPanel panel = new JPanel();
		panel.add(yes);
		add(panel);
		
		yes.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e11)
			{
				setVisible(false);
			}
		});
		
		setSize(300,150);
	}	
}

